<?php
/*
 * @TUDO 实例化数据层
 * @AUTHOR zhouyang
 * @DATE 2013-7-16
 */
class Model
{
	private $model;
    protected $reader;

    //初始化
    public function __construct($model = '')
    {
		$this->model = $model ? $model : substr(get_class($this), 0, -5);
        $this->reader = $this->reader ? $this->reader : $this->model;
    }

    //实例化数据层
    static public function getInstance($model)
    {
        static $instances = array();

        if (! isset($instances[$model]))
        {

            $classname = str_replace(' ', '', ucwords($model.'Model'));
            if (file_exists(MODEL_PATH . $classname . '.php'))
            {
                include MODEL_PATH . $classname . '.php';
            }

            $instances[$model] = new $classname($model);
        }
        return $instances[$model];
    }

    //实例化DB
    final public function dbreader() {
		return DBReader::getInstance($this->reader);
	}

    //实例化MEMCACHE
    final public function memcachereader(){
        return MemcacheReader::getInstance($this->reader);
    }

    //实例化SESSION
    final public function session(){
        return Session::getInstance();
    }

    final public function input(){
        return Input::getInstance();
    }
}


?>